package com.songlanyun.modules.ship.service.impl;

import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.modules.ship.entity.OrderPackage;
import com.songlanyun.modules.ship.model.dto.ExpressShipDTO;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.Query;

import com.songlanyun.modules.ship.dao.OrderPackageExpressDao;
import com.songlanyun.modules.ship.entity.OrderPackageExpress;
import com.songlanyun.modules.ship.service.OrderPackageExpressService;

@Service("orderPackageExpressService")
public class OrderPackageExpressServiceImpl extends ServiceImpl<OrderPackageExpressDao, OrderPackageExpress> implements OrderPackageExpressService {

    @Override
    public OrderPackageExpress create(OrderPackageExpress entity) {
        ValidatorUtils.validateEntity(entity);
        this.baseMapper.insert(entity);
        return entity;
    }

    @Override
    public OrderPackageExpress modify(OrderPackageExpress entity) {
        ValidatorUtils.validateEntity(entity);
        this.baseMapper.updateById(entity);
        return entity;
    }

    /**
     * 创建订单物流包裹的物流信息(内部调用)
     * @param orderPackage
     * @param dto
     * @return
     */
    @Override
    public OrderPackageExpress create(OrderPackage orderPackage, ExpressShipDTO dto) {
        //创建订单物流包裹的物流信息
        OrderPackageExpress orderPackageExpress = new OrderPackageExpress();
        orderPackageExpress.setGoodsPackageId(orderPackage.getId());
        orderPackageExpress.setExpressCode(dto.getExpressCode());
        orderPackageExpress.setExpressName(dto.getExpressName());
        orderPackageExpress.setLogisticCode(dto.getLogisticCode());
        orderPackageExpress.setLastQueryTime(0L);
        orderPackageExpress.setQueryResult("");
        this.create(orderPackageExpress);
        return orderPackageExpress;
    }



    @Override
    public void remove(Long id) {

    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<OrderPackageExpress> page = this.page(
                new Query<OrderPackageExpress>().getPage(params),
                new QueryWrapper<OrderPackageExpress>()
        );

        return new PageUtils(page);
    }


}
